package drds.server.net.packet;

import java.nio.ByteBuffer;

import drds.server.net.SessionContext$LifeCycle;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public abstract class Packet {
	/**
	 * 命令
	 */
	public static final byte QUIT = 2;
	public static final byte KILL_PROCESS = 3;
	public static final byte PING = 4;
	public static final byte HEARTBEAT = 5;
	//
	public static final byte QUERY = 6;
	//
	public static final byte STATEMENT_PREPARE = 7;
	public static final byte STATEMENT_EXECUTE = 8;
	public static final byte STATEMENT_RESET = 9;
	public static final byte STATEMENT_CLOSE = 10;

	/**
	 * mysql_stmt_send_long_data
	 */
	public static final byte COM_STMT_SEND_LONG_DATA = 11;
	// 包头大小
	public static final int packetHeaderSize = 4;

	public int packetLength;
	public byte packetId;

	/**
	 * 把数据包写到buffer中，如果buffer满了就把buffer通过前端连接写出 (writeSocketIfFull=true)。
	 */
	public ByteBuffer write(ByteBuffer byteBuffer, SessionContext$LifeCycle sessionContext, boolean writeSocketIfFull) {
		throw new UnsupportedOperationException();
	}

	/**
	 * 计算数据包大小，不包含包头长度。
	 */
	public abstract int computePacketSize();

}